package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysParkingUse;
import com.gec.model.vo.SysParkingUseQueryVo;
import com.gec.system.service.SysParkingUseService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车位使用情况表 前端控制器
 * </p>
 *
 * @author Liangxj
 * @since 2023-12-06
 */
@Api(tags = "车位使用控制器")
@RestController
//"/admin/system/sysParkingUse/addParking
@RequestMapping("/admin/system/sysParkingUse")
public class SysParkingUseController {

    @Autowired
    private SysParkingUseService sysParkingUseService;


    @ApiOperation("分页查询车位使用情况")
    @GetMapping("/{page}/{limit}")
    public Result findPage(@PathVariable Long page,
                           @PathVariable Long limit,
                           SysParkingUseQueryVo vo){

        IPage<SysParkingUse> page1 = new Page<>(page,limit);
        page1 = this.sysParkingUseService.selectPage(page1,vo);
        return Result.ok(page1);
    }

    //查看全部
    @ApiOperation("全部车位使用信息")
    @GetMapping("/findAll")
    public Result findAll() {
        List<SysParkingUse> list = this.sysParkingUseService.list();
        return Result.ok(list);
    }

    //    新增
    @ApiOperation("新增车位使用")
    @PostMapping("/addParkingUse")
    public Result addParkingUse(@RequestBody SysParkingUse sysParkingUse) {
        boolean res = this.sysParkingUseService.save(sysParkingUse);
        if (res) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    // 修改
    //1.根据id 去得到当前分类
    @ApiOperation("根据id获取车位使用情况")
    @GetMapping("/findParkingUseById/{id}")
    public Result findParkingUseById(@PathVariable Long id)
    {
        SysParkingUse sysParkingUse = this.sysParkingUseService.getById(id);
        return Result.ok(sysParkingUse);
    }

    // 实现修改
    @ApiOperation("修改车位使用情况")
    @PostMapping("/updateParkingUse")
    public Result updateParkingUse(@RequestBody SysParkingUse sysParkingUse)
    {
        boolean b = this.sysParkingUseService.updateById(sysParkingUse);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }

    //    根据单个id 删除数据
    @ApiOperation("根据id删除账号")
    @DeleteMapping("removeParkingUseById/{id}")
    public Result removeParkingUseById(@PathVariable Long id){

        boolean b = this.sysParkingUseService.removeById(id);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

    // 批量删除
    @ApiOperation("批量删除车位使用")
    @DeleteMapping("/removeParkingUseByIds")
    public Result removeParkingUseByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.sysParkingUseService.removeByIds(ids);

        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }



}

